#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project  : ecshop-gitee
# @File     : page_ecshop_back_distribution_mode.py
# @Author   : LiuLei
# @Time     : 2021/7/3 13:55
from selenium.webdriver.common.by import By
import time

from selenium.webdriver.support.select import Select


class PageEcshopBackInstallDistributionMode():

    def __init__(self, driver):
        self.driver = driver

        self.loc_ecshop_install = (By.XPATH, '//div[@id="listDiv"]/table/tbody/tr[2]/td[8]/a')
        self.loc_ecshop_install_username = (
            By.XPATH, '/html/body/div[1]/form/fieldset[1]/table/tbody/tr[1]/td[2]/input')
        self.loc_ecshop_install_limit = (By.XPATH, '//tr[@id="free_money"]/td[2]/input')
        self.loc_ecshop_install_click = (
            By.XPATH, '/html/body/div[1]/form/fieldset[2]/table/tbody/tr[2]/td/span[5]/input')

        self.loc_ecshop_install_sure = (By.XPATH, '/html/body/div[1]/form/table/tbody/tr/td/input[1]')

    def back_ecshop_install(self):
        """
        1.点击查看按钮
        2.点击生成订单
        """
        time.sleep(2)
        # 点击安装按钮
        self.driver.find_element(*self.loc_ecshop_install).click()
        time.sleep(3)
        # 在地址栏输入“成都市锦江区”
        self.driver.find_element(*self.loc_ecshop_install_username).send_keys("成都市锦江区")
        # 选择中国
        element = self.driver.find_element(By.XPATH, '//select[@id="selCountries"]')
        Select(element).select_by_value('1')
        # 选择四川省
        element = self.driver.find_element(By.XPATH, '//select[@id="selProvinces"]')
        Select(element).select_by_value('24')
        # 选择成都市
        element = self.driver.find_element(By.XPATH, '//select[@id="selCities"]')
        Select(element).select_by_value('271')
        # 选择锦江区
        element = self.driver.find_element(By.XPATH, '//select[@id="selDistricts"]')
        Select(element).select_by_value('2713')
        # 选择添加
        self.driver.find_element(*self.loc_ecshop_install_click).click()
        # 点击确定按钮
        self.driver.find_element(*self.loc_ecshop_install_sure).click()

    def back_ecshop_create_oder(self):
        self.back_ecshop_install()
